using System;
using System.Collections.Generic;
using System.Text;

namespace Planar.PT120
{
    public class Command
    {
        private CommandType _CommandType = CommandType.Unknown;
        public CommandType CommandType
        {
            get { return _CommandType; }
        }
        private int _X = int.MinValue;
        public int X
        {
            get { return _X; }
        }
        private int _Y = int.MinValue;
        public int Y
        {
            get { return _Y; }
        }

        public Command(string Data)
        {
            if (Data.Length == 10)
            {
                switch (Data[0])
                {
                    case ('R'):
                        {
                            _CommandType = CommandType.Release;
                            break;
                        }
                    case ('T'):
                        {
                            _CommandType = CommandType.Touch;
                            break;
                        }
                }
                if (_CommandType != CommandType.Unknown)
                {
                    Data = Data.Substring(1, 9);
                    string[] point = Data.Split(',');
                    if (point.Length == 2)
                    {
                        _X = Convert.ToInt32(point[0]);
                        _Y = Convert.ToInt32(point[1]);
                    }
                    else
                    {
                        _CommandType = CommandType.Unknown;
                    }
                }
            }
        }

        public override string ToString()
        {
            return string.Format("{0} x:{1} y:{2}", _CommandType.ToString(), _X, _Y);
        }
    }
}
